import { BaseModel } from './BaseModel.js';
import { dataFiles } from '../config/database.js';

const defaultRoles = [
    {
        id: 1,
        name: '超级管理员',
        code: 'admin',
        description: '系统超级管理员，拥有所有权限',
        status: 'active',
        createdAt: new Date().toISOString(),
        updatedAt: new Date().toISOString()
    },
    {
        id: 2,
        name: '教师',
        code: 'teacher',
        description: '教师角色，可以管理学生、成绩、考勤等',
        status: 'active',
        createdAt: new Date().toISOString(),
        updatedAt: new Date().toISOString()
    },
    {
        id: 3,
        name: '学生',
        code: 'student',
        description: '学生角色，只能查看自己的信息',
        status: 'active',
        createdAt: new Date().toISOString(),
        updatedAt: new Date().toISOString()
    }
];

export class Role extends BaseModel {
    constructor() {
        super(dataFiles.roles, defaultRoles);
    }

    findByCode(code) {
        return this.findOne({ code });
    }

    findByStatus(status) {
        return this.findAll().filter(role => role.status === status);
    }
}

